'use strict';
/**
 * Created by QianQi on 2019/1/21.
 */
$(function(){
    var jqContain = $('.js-contain'),
        jqWidth = jqContain.find('[name="width"]'),
        jqHeight = jqContain.find('[name="height"]'),
        jqWScale = jqContain.find('[name="wScale"]'),
        jqHScale = jqContain.find('[name="hScale"]');
    var fOnSubmitClick = function(){
        fSetVal(jqWidth.val(), jqHeight.val(), jqWScale.val(), jqHScale.val());
    };
    var fSetVal = function(width, height, wScale, hScale){
        var error = false;
        width = parseInt(width, 10);
        height = parseInt(height, 10);
        wScale = parseFloat(wScale);
        hScale = parseFloat(hScale);
        // 宽
        if(isNaN(width) || width <= 0){
            width = '请输入>0的数字';
            error = true;
        }
        jqWidth.val(width);
        // 高
        if(isNaN(height) || height <= 0){
            height = '请输入>0的数字';
            error = true;
        }
        jqHeight.val(height);
        // 横向比例
        if(isNaN(wScale) || wScale <= 0){
            wScale = '请输入>0的数字';
            error = true;
        }
        jqWScale.val(wScale);
        // 纵向比例
        if(isNaN(hScale) || hScale <= 0){
            hScale = '请输入>0的数字';
            error = true;
        }
        jqHScale.val(hScale);
        // 应用样式
        if(!error){
            jqContain.css({
                width: width + 'px',
                height: height + 'px',
                webkitTransform: 'scale(' + wScale + ',' + hScale + ')',
                msTransform: 'scale(' + wScale + ',' + hScale + ')',
                mozTransform: 'scale(' + wScale + ',' + hScale + ')',
                oTransform: 'scale(' + wScale + ',' + hScale + ')',
                transform: 'scale(' + wScale + ',' + hScale + ')'
            });
        }
    };
    /** ============ **/
    $('.js-submit').on('click', fOnSubmitClick);
    fSetVal(1024, 768, 1, 1);
});